package bm.com.project.server.common.service.impl;

import bm.com.project.server.common.converter.AdjunctsConvent;
import bm.com.project.server.common.dto.BmAdjunctsDTO;
import bm.com.project.server.common.entity.BmAdjunctsEntity;
import bm.com.project.server.common.mapper.BmAdjunctsMapper;
import bm.com.project.server.common.service.BmAdjunctsService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;

import java.util.List;

@Service("bmAdjunctsService")
public class BmAdjunctsServiceImpl extends ServiceImpl<BmAdjunctsMapper, BmAdjunctsEntity> implements BmAdjunctsService {

    @Resource
    BmAdjunctsMapper bmAdjunctsMapper;

    /**
     * 通过数据源和业务类型，获取附件信息
     * @param sourceId
     * @param workType
     * @return
     */
    @Override
    public List<BmAdjunctsEntity> getListByType(String sourceId, int workType){

        QueryWrapper<BmAdjunctsEntity> query = new QueryWrapper<>();
        query.eq("sourceId", sourceId);
        query.eq("workType", workType);

        return bmAdjunctsMapper.selectList(query);
    }

    /**
     * 保存附件信息
     * @param dto
     * @return
     */
    @Override
    public boolean saveAdjunct(BmAdjunctsDTO dto){
        BmAdjunctsEntity entity = AdjunctsConvent.INSTANCE.converter(dto);
        return save(entity);
    }

    /**
     * 保存附件信息
     * @param bmAdjunctsEntity
     * @return
     */
    @Override
    public boolean saveBatchAdjunct(List<BmAdjunctsDTO> bmAdjunctsEntity){
        List<BmAdjunctsEntity> entities = AdjunctsConvent.INSTANCE.converterList(bmAdjunctsEntity);
        return saveOrUpdateBatch(entities);
    }
}